<?php


namespace api\web\controller;


use api\web\model\BannerModel;
use cmf\controller\RestBaseController;

class BannerController extends RestBaseController
{
    //轮播图查询
    public function index(){
        $list =BannerModel::select();
        $this->success('首页轮播图管理',$list);
    }
    //轮播图上传
    public function upload(){
        $id = input('id');
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('image');
        // 上传到本地服务器
        $savename = \think\facade\Filesystem::disk('public')->putFile( 'BannerImage', $file,'md5');
        $image2 =   request()->domain().DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.$savename;
        $addImage = BannerModel::where('id','=',$id)->find();
        $addImage->image = $savename;
        if ($addImage->save()){
            return json(['code' => 1, 'msg' => "上传成功" , 'data' => ['url' => $image2,]]);
        }else{
            return json(['code' => 0,'msg' => "上传失败" , 'data' => null]);
        }
    }
}